<template>
  <div class="app-container">
    <el-card shadow="never">
      <el-form :inline="true" :model="searchForm" class="search-form">
        <el-form-item label="患者姓名">
          <el-input v-model="searchForm.nickname" clearable>
          </el-input>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model="searchForm.contactPhone" clearable>
          </el-input>
        </el-form-item>
        <el-form-item label="身份证号">
          <el-input v-model="searchForm.contactPhone" clearable>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleFilter" class="search-button">查询</el-button>
          <el-button @click="handleReset" class="search-button">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" fit highlight-current-row>
        <el-table-column align="center" type="index" label="序号" width="55">
        </el-table-column>
        <el-table-column label="患者" align="center" prop="client">
        </el-table-column>
        <el-table-column label="身份证号" align="center" prop="idNum">
        </el-table-column>
        <el-table-column label="区域" align="center" prop="detailedAddress">
        </el-table-column>
        <el-table-column label="性别" align="center" prop="sex">
        </el-table-column>
        <el-table-column label="所属医院" align="center" prop="hospitalName">
        </el-table-column>
        <el-table-column label="手机号" align="center" prop="contactPhone">
        </el-table-column>
        <el-table-column label="生日" align="center" prop="birthDate">
        </el-table-column>
        <el-table-column label="上门地址" align="center" prop="serviceAddress">
        </el-table-column>
        <el-table-column label="是否过敏" align="center" prop="isHistoryAllergies">
        </el-table-column>
        <el-table-column label="是否有常见病或慢性病" align="center" prop="isChronicDisease">
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime">
        </el-table-column>
        <!--  <el-table-column align="center" label="操作" width="200">
          <template slot-scope="{row}">
             <el-button @click="showEdit(row)" type="text">详情</el-button>
          </template>
        </el-table-column>-->
      </el-table>
      <pagination v-show="total > 0" :total="total" :page.sync="searchForm.pageIndex" :limit.sync="searchForm.pageSize"
        @pagination="getList" />
    </el-card>
  </div>
</template>

<script>
//import * as patientInfo from '@/api/patientInfo'
import Pagination from '@/components/Pagination'
export default {
  components: { Pagination },
  data () {
    return {
      list: null,
      listLoading: false,
      searchForm: {
        pageIndex: 1,
        pageSize: 10
      },
      total: 0,
      dialogVisible: false,
      dialogTit: '',
      form: {},
      selectionData: []
    }
  },
  created () {
    //this.getList()
  },
  methods: {
    getList () {
      this.listLoading = true
      let param = Object.assign({}, this.searchForm)
      param.hospitalUid = localStorage.getItem('hospitalUid')
      patientInfo.queryByPage(param).then(response => {
        this.list = response.data.rows
        this.total = response.data.total
        this.listLoading = false
      }).catch(error => {
        this.listLoading = false
        console.log(error)
      })
    },
    handleFilter () {
      this.searchForm.pageIndex = 1
      this.getList()
    },
    handleReset () {
      this.resetTemp();
      this.getList();
    },
    resetTemp () {
      this.searchForm = {
        pageIndex: 1,
        pageSize: 10
      }
    },
    showEdit (row) {
      this.dialogTit = '编辑'
      this.form = Object.assign({}, row)
      delete this.form.createTime
      delete this.form.updateTime
      this.dialogVisible = true
    },
    editHandle () {
      consumable.update(this.form).then(response => {
        if (response.code == 200) {
          this.dialogVisible = false
          this.getList()
          this.$message.success('修改成功')
        }
      }).catch(error => {
        console.log(error)
      })
    },
    close (msg) {
      if (msg === '') {
        this.dialogVisible = false
      } else {
        let batchUses = msg
        batchUses.map(item => {
          delete item.createTime
          delete item.updateTime
        })
        consumable.batchInsert({ batchUses: batchUses }).then(response => {
          if (response.code == 200) {
            this.dialogVisible = false
            this.getList()
            this.$message.success('新增成功')
          }
        }).catch(error => {
          this.$message.error(error)
          console.log(error)
        })
      }
    }
  }
}
</script>
